#include "eventfilter.h"
#include "utils.h"

#include <QEvent>
#include <QDropEvent>
#include <QDragEnterEvent>
#include <QDragLeaveEvent>
#include <QDragMoveEvent>
#include <QMimeData>
#include <QDrag>

EventFilter::EventFilter(QObject *parent) : QObject(parent)
{
}

bool EventFilter::eventFilter(QObject *obj, QEvent *event)
{
    switch (event->type())
    {
    case QEvent::MouseButtonPress:
    case QEvent::MouseButtonRelease:
    case QEvent::MouseButtonDblClick:
    case QEvent::FocusIn:
    case QEvent::FocusOut:
    case QEvent::FocusAboutToChange:
    case QEvent::DragEnter:
    case QEvent::DragLeave:
    case QEvent::Drop:
        if (event->type() == QEvent::DragEnter) {
            QDragEnterEvent *ev = static_cast<QDragEnterEvent *>(event);
            ev->acceptProposedAction();
            DEBUG() << "Event:" << event->type() << "Cursor POS:" << ev->pos();
        } else if (event->type() == QEvent::Drop) {
            QDropEvent *ev = static_cast<QDropEvent *>(event);
            DEBUG() << "Event:" << event->type() << "Action:" << ev->dropAction() << "POS:" << ev->pos() << "Data:" << ev->mimeData()->text() << "Format:" << ev->mimeData()->formats();
        } else {
            DEBUG() << "Event:" << event->type();
        }
        fflush(stderr);
        fflush(stdout);
    default:
        break;
    }

    return QObject::eventFilter(obj, event);
}
